home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 916 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: cix.compulink.co.uk!usenet
  3. From: henri@cix.compulink.co.uk ("Henry Andrew")
  4. Subject: Re: two tricky questions
  5. Message-ID: <DKv098.7JE@cix.compulink.co.uk>
  6. Organization: Compulink Information eXchange
  7. References: <4cnan0$gqv@news.xmission.com>
  8. Date: Mon, 8 Jan 1996 11:07:55 GMT
  9. X-News-Software: Ameol32
  10.  
  11. Umm . . .
  12. It could be that some compilers do it as a bitwise copy but the compiler 
  13. I am currently using (IBM CSet++ on AIX) does a memberwise copy.
  14. And in so doing, it seems to me, follow Stroustrup.
  15.  
  16. Try the following code:
  17. #include <iostream.h>
  18. class B { public:
  19.     int _i;
  20.     B(const B & b) { _i = b._i + 1;}
  21.     B(int i=10) : _i(i) {}};
  22.     
  23. class A { public: B _b;
  24.     A(int 1=20) : _b(i) {}};
  25.     
  26. void main(void)
  27.     {
  28.     A a1;
  29.     A a2(a1);
  30.     cout << a1._b._i << '\t' << a2._b._i << endl;
  31.     }
  32.  
  33. mine prints "20 21"
  34. a default copy of the bitmap would give "20     20"
  35.  
  36. Refs.
  37.  
  38. Grey book
  39. r.12.8
  40. ". . . If not defined by the programmer, they will be defined as 
  41. memberwise assignment and memberwise initialization of the members of X, 
  42. respectively."
  43.  
  44. and (somewhat to my surprise)
  45.  
  46. ARM
  47. 12.8
  48. ". . . If not defined by the programmer, they will be defined as 
  49. memberwise assignment and memberwise initialization of the members of X, 
  50. respectively."
  51.  
  52. Yours &c. Henry
  53.